﻿using DCode.EmailValidator.Core;
using DCode.EmailValidator.UI.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DCode.EmailValidator.UI.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            return View(new HomeModel());
        }

        [HttpPost]
        public ActionResult Index(HomeModel model)
        {
            if (ModelState.IsValid)
            {
                var response = "";

                using (var validator = new Validator())
                {
                    var result = validator.ValidateMail(model.EmailAddress);

                    if (result.IsValid)
                        response = "Correo OK";
                    else
                        response = "Correo NOK";
                }

                return View(new HomeModel() { GeneralMessage = response});
            }

            return View();
        }
    }
}